﻿<Page
    x:Class="DvachBrowser3.Views.CatalogPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:DvachBrowser3.Views"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:vm="using:DvachBrowser3.ViewModels"
    xmlns:pa="using:DvachBrowser3.Views.Partial"
    xmlns:behaviors="using:Template10.Behaviors"
    xmlns:ps="using:DvachBrowser3.PageServices"
    xmlns:localBehaviors="using:DvachBrowser3.Behaviors"
    xmlns:controls="using:Template10.Controls"
    xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
    xmlns:core="using:Microsoft.Xaml.Interactions.Core"
    mc:Ignorable="d" x:Name="ThisPage" KeyDown="CatalogPage_OnKeyDown">

    <ps:PageServices.Services>
        <ps:PageServiceCollection>
            <ps:ShellAppBarPageService />
            <ps:ViewModelLifetimePageService />
        </ps:PageServiceCollection>
    </ps:PageServices.Services>

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

        <VisualStateManager.VisualStateGroups>
            <VisualStateGroup x:Name="VisualStateGroup">
                <VisualState x:Name="VisualStateNarrow">
                    <VisualState.StateTriggers>
                        <AdaptiveTrigger MinWindowWidth="{StaticResource NarrowMinWidth}" />
                    </VisualState.StateTriggers>
                    <VisualState.Setters>
                        <Setter Target="PostPreviewScroll.Padding" Value="{StaticResource CleanListPaddingNarrow}" />
                    </VisualState.Setters>
                </VisualState>
                <VisualState x:Name="VisualStateNormal">
                    <VisualState.StateTriggers>
                        <AdaptiveTrigger MinWindowWidth="{StaticResource NormalMinWidth}" />
                    </VisualState.StateTriggers>
                    <VisualState.Setters>
                        <Setter Target="PostPreviewScroll.Padding" Value="{StaticResource CleanListPadding}" />
                    </VisualState.Setters>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>

        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="100*"/>
        </Grid.RowDefinitions>

        <!--  header  -->
        <controls:PageHeader BackButtonVisibility="Collapsed" Frame="{x:Bind Frame, Mode=OneWay}" FontWeight="Bold"
                             Content="КАТАЛОГ">
            <interactivity:Interaction.Behaviors>
                <behaviors:EllipsisBehavior Visibility="Collapsed" />
            </interactivity:Interaction.Behaviors>
            <controls:PageHeader.PrimaryCommands>
                <AppBarToggleButton Label="Поиск" IsEnabled="{x:Bind ColViewModel.HasData, Mode=OneWay}" x:Name="FilterButton" RequestedTheme="Dark" Style="{StaticResource HeaderAppBarToggleButtonStyle}">
                    <AppBarToggleButton.Icon>
                        <SymbolIcon Symbol="Find" />
                    </AppBarToggleButton.Icon>
                </AppBarToggleButton>
            </controls:PageHeader.PrimaryCommands>
        </controls:PageHeader>
        <pa:SearchBox Grid.Row="1" x:Name="FilterBox" FilterUpdated="FilterBox_OnFilterUpdated" VerticalAlignment="Top" AnimatedVisibility="{Binding ElementName=FilterButton, Path=IsChecked, Mode=OneWay, Converter={StaticResource BoolToVisibilityConverter}, ConverterParameter=false}" />
        <pa:ProgressIndicatorControl Grid.Row="2" ViewModel="{x:Bind ColViewModel.Update.Progress, Mode=OneWay}" ShowMessage="True" />
        <GridView x:Name="MainList" Grid.Row="3" SelectionMode="None" ItemsSource="{x:Bind FilteredPosts.Posts, Mode=OneWay}" Margin="4, 4, 4, 0"
                  >
            <GridView.Header>
                <TextBlock Text="{x:Bind ViewModel.Title, Mode=OneWay}" FontWeight="SemiBold" FontSize="{x:Bind ViewModel.StyleManager.Text.TitleFontSize, Mode=OneWay}" MaxLines="2" Margin="0, 0, 0, 10" HorizontalAlignment="Center" TextWrapping="Wrap" />
            </GridView.Header>
            <GridView.ItemTemplate>
                <DataTemplate x:DataType="vm:IPostViewModel">
                    <Grid Width="{x:Bind StyleManager.Tiles.CatalogTileWidth, Mode=OneWay}" Margin="0, 0, 0, 7.5" ToolTipService.ToolTip="{x:Bind Subject}" Tapped="CatalogElement_OnTapped"
                          Tag="{x:Bind Mode=OneWay}">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"></RowDefinition>
                            <RowDefinition Height="Auto"></RowDefinition>
                        </Grid.RowDefinitions>
                        <TextBlock Grid.Row="0" FontSize="{x:Bind StyleManager.Text.SmallFontSize, Mode=OneWay}" TextTrimming="CharacterEllipsis" TextWrapping="NoWrap" HorizontalAlignment="Left" Margin="2" Text="{x:Bind Subject, Mode=OneWay}" />
                        <pa:TileImage Grid.Row="1" ViewModel="{x:Bind Media.PrimaryFile.ThumbnailImage, Mode=OneWay}" Height="{x:Bind StyleManager.Tiles.CatalogTileHeight, Mode=OneWay}" HorizontalAlignment="Stretch" />
                    </Grid>
                </DataTemplate>
            </GridView.ItemTemplate>
        </GridView>
        <pa:ContentPopup x:Name="PostPreview" Grid.Row="2" Grid.RowSpan="2">
            <pa:ContentPopup.ViewContent>
                <ScrollViewer HorizontalScrollBarVisibility="Disabled" Grid.Row="0" HorizontalAlignment="Stretch" x:Name="PostPreviewScroll">
                    <pa:PostView x:Name="PostView" MaxLines="0" ShowFullThreadText="Перейти в тред" ShowPreviewSeparator="True" ShowCounter="False"
                                 ShowFullThread="PostView_OnShowFullThread"/>
                </ScrollViewer>
            </pa:ContentPopup.ViewContent>
        </pa:ContentPopup>
    </Grid>
</Page>

